<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Services\FeedbackService;
use Illuminate\Http\Request;

class Feedback extends Controller
{
    // 反馈 服务
    public $feedbackSercice;

    /**
     * 构造方法
     * Feedback constructor.
     */
    public function __construct()
    {
        $this->feedbackSercice = new FeedbackService();
    }

    /**
     * @return array
     * @author 董宗澳
     * @email 2453611300@qq.com
     * 获取反馈列表
     */
    public function index()
    {
        return $this->feedbackSercice->getList();
    }

    /**
     * @param $id 反馈id
     * @return array
     * @author 董宗澳
     * @email 2453611300@qq.com
     */
    public function show($id)
    {
        try {
            return $this->feedbackSercice->show($id);
        } catch (\Exception $e) {
            return $this->error('获取失败' . $e->getMessage());
        }
    }

    /**
     * @param Request $request
     * @param \App\Models\Feedback $feedback
     * @param Request $request- >id 某条反馈 id
     * 修改是否已读
     * @return array
     * @author 董宗澳
     * @email 2453611300@qq.com
     */
    public function edit_feedback_info_show(Request $request, \App\Models\Feedback $feedback)
    {
        $id = $request->post('id');
        $data = $feedback->where('id', $id)->first();
        $feedbackStatus = $data['is_read'] == 1 ? 0 : 1;
        $data->is_read = $feedbackStatus;
        return $data->save() ? $this->success([], '修改成功!') : $this->error([], '修改失败!');
    }


    /**
     * 析构方法
     */
    public function __destruct()
    {
        $this->feedbackSercice;
        // TODO: Implement __destruct() method.
    }
}
